package com.wlscale.roadsystem.wiget;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.wlscale.roadsystem.R;


/**
 * 描述: {修改密码}
 * 作者: jack-song
 * 创建日期: 2017/11/7 10:04
 * 修改日期: 2017/11/7
 * 版本: {版本}
 */
public class EditOperatorDialog extends Dialog {
    /**
     * 左侧按钮
     */
    private Button btnLeft;
    /**
     * 右侧按钮
     */
    private Button btnRigth;
    /**
     * 按钮
     */
    private OnClickLister onClickLister;

    public EditOperatorDialog(@NonNull Context context) {
        super(context);
    }

    public EditOperatorDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    @SuppressLint("WrongViewCast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_edit_operator);
        btnLeft = findViewById(R.id.btn_left);
        btnRigth = findViewById(R.id.btn_rigth);
        btnLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        btnRigth.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });

    }

    public void setOnClickLister(OnClickLister onClickLister) {
        this.onClickLister = onClickLister;
    }

    @Override
    public void onStart() {
        super.onStart();
        Window window = getWindow();
        WindowManager wm = window.getWindowManager();
        Point windowSize = new Point();
        wm.getDefaultDisplay().getSize(windowSize);
        window.getAttributes().width = (int) (windowSize.x * 0.8f);
        window.getAttributes().height = ViewGroup.LayoutParams.WRAP_CONTENT;
        window.setGravity(Gravity.CENTER);

    }


    public static class Builder {
        /**
         * 上下文
         */
        private Context context;
        /**
         * 按钮
         */
        private OnClickLister onClickLister;

        public Builder() {
        }

        public Builder setContext(Context context) {
            this.context = context;
            return this;
        }

        public Builder setOnClickLister(OnClickLister onClickLister) {
            this.onClickLister = onClickLister;
            return this;
        }

        public EditOperatorDialog builder() {
            EditOperatorDialog loadingDialog = new EditOperatorDialog(context, R.style.loading_dialog);
            loadingDialog.setOnClickLister(onClickLister);
            return loadingDialog;
        }
    }

    public interface OnClickLister {
        void onClickLister(String locAddress);
    }
}
